#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2018, Niklas Hauser
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.


def init(module):
    module.name = ":test:platform:bitbang"
    module.description = "Tests for BitBang"


def prepare(module, options):
    # Disable this test until a more robust logic analyzer solution can be found
    return False

    target = options[":target"]
    core = target.get_driver("core:cortex-m*")
    # Cortex-M0 doesn't have the DWT->CYCCNT and Cortex-M7 support is broken
    if not core or "m0" in core["type"] or "m7" in core["type"]:
        return False
    if target.identifier.platform != "stm32":
        return False
    # Only 64-pin TQFP package
    if target.identifier.pin != "r" or target.identifier.package != "t":
        return False

    module.depends(
        ":platform:spi.bitbang",
        ":driver:gpio_sampler")
    return True


def build(env):
    if not env.has_module(":board:nucleo-*"):
        env.log.warn("`:test:platform:spi.bitbang` has been hardcoded to a Nucleo-64 board!")
        # When porting make sure this test does not damage your board!
        return

    global tim_instance
    env.outbasepath = "modm-test/src/modm-test/platform/spi"
    env.copy("spi_bitbang_test.hpp")
    env.copy("spi_bitbang_test.cpp")
